package com.lgx.mall.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lgx.common.entity.IntraCity;
import com.lgx.common.web.Constants;
import com.lgx.mall.core.vo.ProductVO;
import com.lgx.mall.view.service.IWebPageDetailService;

/**
 * 首页控制器
 * 
 * @author acer
 *
 */
@Controller
@RequestMapping("/home")
public class HomeController {
	
	@Autowired
	private IWebPageDetailService webPageDetailService;
	
	public IWebPageDetailService getWebPageDetailService() {
		return webPageDetailService;
	}

	public void setWebPageDetailService(
			IWebPageDetailService webPageDetailService) {
		this.webPageDetailService = webPageDetailService;
	}

	/**
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/head.ftl")
	public String head(HttpServletRequest request,HttpServletResponse response){
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);
		
		return "home/head";
	}
	
	/**
	 * 首页广告
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/hot-screen.ftl")
	public String hotScreen(HttpServletRequest request,HttpServletResponse response){
		long categoryId = 103;
		List<ProductVO> details1 = this.webPageDetailService.findProductVOByAreaAndCid(null, categoryId);
		categoryId = 105;
		List<ProductVO> details2 = this.webPageDetailService.findProductVOByAreaAndCid(null, categoryId);
		
		request.setAttribute("details1", details1);
		request.setAttribute("details2", details2);
		
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);
		
		return "home/hot-screen";
	}

	/**
	 * 新品推荐
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/new-screen.ftl")
	public String newScreen(HttpServletRequest request,HttpServletResponse response){
		
		long categoryId = 106;
		List<ProductVO> details1 = this.webPageDetailService.findProductVOByAreaAndCid(null, categoryId);
		categoryId = 133;
		List<ProductVO> details2 = this.webPageDetailService.findProductVOByAreaAndCid(null, categoryId);
		
		request.setAttribute("details1", details1);
		request.setAttribute("details2", details2);
		
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);
		
		return "home/new-screen";
	}
	
	/**
	 * 通栏广告
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/ad-1000.ftl")
	public String ad1000(HttpServletRequest request,HttpServletResponse response){
		long categoryId = 107;
		List<ProductVO> details = this.webPageDetailService.findProductVOByAreaAndCid(null, categoryId);
		request.setAttribute("details", details);
		
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);
		
		return "home/ad-1000";
	}
	
	/**
	 * 共享优品
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/excellent-product.ftl")
	public String excellentProduct(HttpServletRequest request,HttpServletResponse response){
		long categoryId = 108;
		List<ProductVO> details = this.webPageDetailService.findProductVOByAreaAndCid(null, categoryId);
		request.setAttribute("details", details);
		
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);
		
		return "home/excellent-product";
	}
	
	/**
	 * 共享名品
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/famous-brand.ftl")
	public String famousBrand(HttpServletRequest request,HttpServletResponse response){
		long categoryId = 109;
		List<ProductVO> details1 = this.webPageDetailService.findProductVOByAreaAndCid(null, categoryId);
		request.setAttribute("details1", details1);
		
		categoryId = 143;
		List<ProductVO> details2 = this.webPageDetailService.findProductVOByAreaAndCid(null, categoryId);
		request.setAttribute("details2", details2);
		
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);
		
		return "home/famous-brand";
	}
	
	/**
	 * 共享奢品
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/luxury-product.ftl")
	public String luxuryProduct(HttpServletRequest request,HttpServletResponse response){
		long categoryId = 110;
		List<ProductVO> details = this.webPageDetailService.findProductVOByAreaAndCid(null, categoryId);
		request.setAttribute("details", details);
		
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);
		
		return "home/luxury-product";
	}
	
	/**
	 * 共享同城
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/city-product.ftl")
	public String cityProduct(HttpServletRequest request,HttpServletResponse response){
		
		//获取同城
		IntraCity city = (IntraCity) request.getSession().getAttribute(Constants.INTRA_CITY_SIGN);
		
		long categoryId = 111;
		List<ProductVO> details1 = this.webPageDetailService.findProductVOByAreaAndCid(city==null?null:city.getAreaId(), categoryId);
		categoryId = 134;
		List<ProductVO> details2 = this.webPageDetailService.findProductVOByAreaAndCid(city==null?null:city.getAreaId(), categoryId);
		categoryId = 135;
		List<ProductVO> details3 = this.webPageDetailService.findProductVOByAreaAndCid(city==null?null:city.getAreaId(), categoryId);
	
		request.setAttribute("details1", details1);
		request.setAttribute("details2", details2);
		request.setAttribute("details3", details3);
		
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);
		
		return "home/city-product";
	}
}
	
